package com.example.demo.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

import com.example.demo.GenericDaoImpl;
import com.example.demo.dao.Selectable;
import com.example.demo.dao.UserDao;
import com.example.demo.model.SysRoleModel;
import com.example.demo.model.SysUserModel;

@Repository("userDao")
public class UserDaoImpl extends GenericDaoImpl<SysUserModel, String> implements UserDao {

	private static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);

	@Autowired
	protected Selectable selectable;

	
	@Override
	public List<SysUserModel> queryUserList(){
		logger.info("查询sql语句："+"select * from sys_user where 1=1");
		return selectable.select(SysUserModel.class,"select * from sys_user where 1=1", null);
	}
	
	
	
	@Override
	public List<SysUserModel> queryLoginName(String loginName){
		logger.info("查询sql语句："+"select * from sys_user where login_name = :loginName ");
		 Map<String, String> allParams = new HashMap<String, String>();
		 allParams.put("loginName", loginName);
		return selectable.select(SysUserModel.class,"select * from sys_user where login_name = :loginName", allParams);
	}
	
 
	

	@Override
	public Page<SysUserModel> queryUserPage(int pageNum,int pageSize){
		Map<String,Object> paramMap = new HashMap<>();
		String limitSql = "select * from sys_user where 1=1  LIMIT :offset, :pageSize  ";
		String countSql = "select count(*) from sys_user";
		
		return selectable.select(SysUserModel.class, limitSql, countSql, paramMap, pageNum, pageSize);
	}

 
	
	
}
